<?php
/**
 * Created by PhpStorm.
 * User: yuyj
 * Date: 16-12-12
 * Time: 上午10:09
 */

namespace common\services\outstock;

use common\entities\outstock\MyscrmOutStockProductEntity;
use common\repositories\outstock\OutStockProductRepository;
use common\services\BaseService;

class OutStockProductService extends BaseService
{
    private $repository;

    public function __construct(OutStockProductRepository $repository, $config = [])
    {
        $this->repository = $repository;

        return parent::__construct($config);
    }

    /**
     * 批量保存
     * @param       $orderId
     * @param array $models
     */
    public function batchSave($orderId, array $models)
    {
        foreach ($models as &$model) {
            if (!$model instanceof MyscrmOutStockProductEntity) {
                $model = new MyscrmOutStockProductEntity();
                $model->setAttribute($model);
            }
        }

        $this->repository->batchSave($orderId, $models);
    }

    /**
     * 获取出库绑定的产品列表
     * @param null $contractCode
     */
    public function getProjectList($contractCode = null)
    {
        $data = [];

        //如果是新增的单据，
        if (empty($data)) {
            //已有合同
            if ($contractCode) {
                //\common\services\myhtsq\ContractService::getProducts
            } else {
            }
        }
    }

    /**
     * @inheritdoc
     */
    public function getProductsByOrderId($orderId)
    {
        return $this->repository->getProductsByOrderId($orderId);
    }

}